from util.events.event import *
from util.events.eventlistener import *
from util.events.eventmanager import *

class NewEvent(Event):
    name = "New Event"

class TestListener1(EventListener):
    def __init__(self, ev):
        super(TestListener1,self).__init__(ev)
        self.eventHandlers = {Event.name : self.test1,
                              TickEvent.name: self.test2}
    def test1(self, event):
        print "%s just got an event: %s"%(self, event.name)
    
    def test2(self, event):
        print "%s is ticking the CPU" %(self)
        
class TestListener2(EventListener):
    def __init__(self, eventManager):
        super(TestListener2, self).__init__(eventManager)
        self.eventHandlers = {Event.name : self.test1,
                              QuitEvent.name: self.test2}
    def test1(self, event):
        print "%s just got an event: %s"%(self, event.name)
    
    def test2(self, event):
        print "%s is now quitting" %(self)

class TestListener3(EventListener):
    def __init__(self, eventManager):
        super(TestListener3, self).__init__(eventManager)
        self.eventHandlers = {Event.name : self.test1}
    
    def test1(self, event):
        print "%s just got an event: %s"%(self, event.name)
        
ev = EventManager()
tl1 = TestListener1(ev)
tl2 = TestListener2(ev)
tl3 = TestListener3(ev)

ev.Post(Event())
ev.Post(TickEvent())
ev.Post(NewEvent())
ev.Post(QuitEvent())
ev.Post(Event())